package com.wujian.love.controller;

import cn.hutool.core.util.ObjectUtil;
import com.wujian.love.contants.ClassContants;
import com.wujian.love.domin.Product;
import com.wujian.love.service.IProductService;
import com.wujian.love.result.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @ClassName: ProductController
 * @description:
 * @author: wujian
 * @Date: 2020-06-17 09:45
 **/
@RestController
@RequestMapping("/love/product")
public class ProductController {

    @Autowired
    private IProductService iProductService;


    /**
     * @Author WuJian
     * @Description 新增商品信息
     * @Date 9:52 2020/6/17
     * @Param [id]
     * @return com.wujian.love.result.JSONResult
     **/
    @PostMapping("/addProduct")
    public JSONResult addProuct(@RequestBody Product info){
        info.setDelFlag(ClassContants.NOT_DEL_FLAG);
        info.setHotFlag(ClassContants.NOT_HOT_FLAG);
        info.setCreateTime(new Date());
        info.setVersion(0);
        iProductService.addProuctForAPP(info);
        return JSONResult.ok();


    }

    /**
     * @Author WuJian
     * @Description 查询商品信息
     * @Date 9:52 2020/6/17
     * @Param [id]
     * @return com.wujian.love.result.JSONResult
     **/
    @GetMapping("/getProduct")
    public JSONResult getProduct(Integer id){
        Product product = iProductService.getProductInfoForAPP(id);
        if(ObjectUtil.isEmpty(product)){
            return JSONResult.errorMsg(JSONResult.NOT_FOUND_DATA);
        }
        return JSONResult.ok(product);
    }





}
